﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Agency_LookBidcompany : System.Web.UI.Page
{

    public string strbidnumber, strbidprice, strbidNoprice,strproject;
    protected void Page_Load(object sender, EventArgs e)
    {
         System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            strproject = SysFun.IsSQL(Request.QueryString["project"].ToString());
             if (strproject == "") return;
            showGridView();
            findbid();
        }
    }
    private void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "Bid_goods_product_cs_tb_agent";
        dbPage.Key = "companyname_tb";
        dbPage.Where = strConditions;                        //
        dbPage.SelectField = "companyname_tb, count(bidid) as sumbid, sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end ) as sumbidprice,(count(bidid)- sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end ))as sumbidNoprice";                             //可以不设，默认为“*”

        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 50;//Request.QueryString["PS"]);
        dbPage.SelectFieldGroup = "companyname_tb";
        switch (DropDownList1.Text)
        {
            case "全部":
              
                 break;
            case "未报完价":
                 dbPage.GroupHaving = " count(bidid) <>sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end ) and sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end )<>0";
                break;
            case  "未报价":
                dbPage.GroupHaving = " sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end )=0";
                break;


        }
       
        System.Data.IDataReader dr = dbPage.ExecuteReaderGroup(30);
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        db.Close();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    private string fctConditions()
    {
        string strtemp = "  projectid=" + strproject + " and checkstatus=1 ";
       // string strname=SysFun.ToName2(TextBox1.Text.Trim());                     //字符转换以后与库中数据不符，查不出数据， 应在导入数据库之前转换。2009年1月8号
        string strname = TextBox1.Text.Trim();
        if (strname!="")
      {
          strtemp += " and companyname_tb like '%" + strname + "%' ";
      }
        
      return strtemp;
    }
    private void findbid()
    {
        string stsele = "select count(bidid) as sumbid, sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end ) as sumbidprice,(count(bidid)- sum( case  when EncryptedPrice IS NOT NULL then 1  else 0 end ))as sumbidNoprice  from Bid_goods_product_cs_tb_agent where checkstatus=1 and projectid=" + strproject;
        Db db = new Db();
        DataTable dt = db.DataTable(stsele);
        db.Close();
         strbidnumber=dt.Rows[0].ItemArray[0].ToString();
         strbidprice=dt.Rows[0].ItemArray[1].ToString();
         strbidNoprice = dt.Rows[0].ItemArray[2].ToString();
    }
}
